<template>
	<view>
		<cu-custom bgColor="bg-gradual-green" :isBack="true"><block slot="backText" @tap="nav">返回</block>
			<block slot="content">调查问卷</block>
		</cu-custom>
		<view style="height: 340upx;">
			<image src="cloud://jianshen-6g5fzx5gfbc2096b.6a69-jianshen-6g5fzx5gfbc2096b-1304015367/3a7f95c2362240a4111a451633a075ea.jpeg" mode="widthFix" style="width: 750upx;"></image>
		</view>
		
		<view class="cu-bar bg-white solid-bottom" 
			@click="jump"
			:data-src="'/pagesA/Questionnaire_add/Questionnaire_add?userId=' + id"
			>
			<view class='action' style="color: #999;">
				<text class='cuIcon-roundaddfill text-blue' style="font-size: 50upx;"></text>添加调查问卷
			</view>
		</view>
		
		<!-- 调查问卷存在,则渲染问卷列表 -->
		<view class="margin-top" v-if="list.length > 0">
			<view 
				class="cu-bar bg-white" 
				style="border-bottom: 2upx solid #F9F9F9;" 
				v-for="(item,index) in list" :key="index" 
				@click="jump" 
				:data-src='"/pagesA/Questionnaire_list/details?id="+item.id'
				>
				<view class="action">
					问卷调查
				</view>
				<view class="action">
					<text class="text-df margin-right-sm" style="color: #999999;">{{item.createTime.substring(0,10)}}</text>
					<text class="cuIcon-right text-gray"></text>
				</view>
			</view>
		</view>
		
		<view v-if="list.length == 0" style="width: 100%;margin: 0 auto;">
			<image src="../../static/11.png" mode="widthFix" style="margin: 200upx auto;display: block;"></image>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[],
				openid:'',
				id: '', // 具体用户id,上一页传入
				tohome: false, // 回到首页
			};
		},
		onLoad:function(e){
			if ( e.id ) {
				this.id = e.id
			}
			if ( e.tohome ) {
				this.tohome = true
			}
			uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					this.setAjax()
				},
				fail: () => {
					uni.reLaunch({
						url: '/pagesA/login/login'
					})
				}
			});
		},
		methods:{
			// 请求问卷对象的问卷列表
			setAjax(){
				var data = {
					'membersId': this.id,
					'coachId': this.openid,
				}
				console.log(data)
				uni.request({
					url:  uni.getStorageSync("baseUrl") + '/coach/members/getUserQuestionnaireSurveyList',
					method: 'GET',
					data: data,
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						uni.hideLoading()
						this.list = res.data.datas
					},
					fail: () => {},
					complete: () => {}
				});
				
			},
			nav () {
				// 在调查问卷 过来的页面返回键跳转到首页
				if (this.tohome) {
					uni.redirectTo({
						url: '/pages/index/index',
					})
				}
			},
			jump(e){
				uni.navigateTo({
					url: e.currentTarget.dataset.src
				});
			},
		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}
</style>
